package com.mm.service.impl;

import com.mm.dao.OrderMapper;
import com.mm.exception.ServiceException;
import com.mm.model.Order;
import com.mm.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单service实现类
 *
 * @date 2018/7/19 15:52
 */
@Service(value = "orderService")
public class OrderServiceImpl implements OrderService {
	@Autowired
	private OrderMapper orderMapper;

	/**
	 * 保存订单
	 *
	 * @param order Order
	 */
	@Override
	public void saveOrder(Order order) {
		order.setAddTime(System.currentTimeMillis());
		orderMapper.insertOrder(order);
	}

	/**
	 * 更新订单
	 *
	 * @param order Order
	 */
	@Override
	public void updateOrder(Order order) {
		orderMapper.updateOrderById(order);
	}

	/**
	 * 获取订单
	 *
	 * @param orderId 订单ID
	 * @return Order
	 * @throws ServiceException
	 */
	@Override
	public Order getOneOrderById(Long orderId) throws ServiceException {
		if (orderId == null) {
			throw new ServiceException("订单ID不能为空");
		}
		return orderMapper.getOneOrderById(orderId);
	}

	/**
	 * 通过订单ID删除订单
	 *
	 * @param orderId 订单ID
	 * @throws ServiceException
	 */
	@Override
	public void deleteOrderById(Long orderId) throws ServiceException {
		if (orderId == null) {
			throw new ServiceException("订单ID不能为空");
		}
		orderMapper.deleteOrderById(orderId);
	}
}
